package simple.demo.springintegration.demo.chapter5;

import java.util.Random;

public class CompareTestApp {
	static final int COUNT = 1024 * 1024;
	
	static final String str = "In computer architecture, cycles per instruction" +
			" (aka clock cycles per instruction, clocks per instruction, or CPI) " +
			"is one aspect of a processor's performance: the number of clock cycles " +
			"that happen when an instruction is being executed. It is the multiplicative " +
			"inverse of instructions per cycle.";
	
	public static String getValue(int v)
	{
		int x = v % str.length();
		return str.substring(0, x);
	}
	
	public static void main(String[] args) {
		Random r = new Random();
		long total = 0;
		String sb = "";
		
		long begin = System.currentTimeMillis();
		
		for(int k=0; k<COUNT; ++k)
		{
			sb = sb + getValue(Math.abs(r.nextInt()));
			total += sb.length();
			if(sb.length() > 1024 * 10)
				sb = "";
		}
		
		long end = System.currentTimeMillis();
		System.out.printf("total = %d, process time = %d", total, (end - begin));

	}

}
